// import http from '../../utils/http'
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit"; 
import { PayloadAction } from "@reduxjs/toolkit";


type Token = string
type Infos = {
    [index: string]: unknown
}
export type UsersState = {
    token: Token
    infos: Infos
}
type Login = {
    email: string
    password: number
}
// 登录接口
export const loginAction = createAsyncThunk('my/loginAction',async (payload:Login) => {
    // const res = await http.post('url', payload)
    // return res
})
// 登录接口
export const infoAction = createAsyncThunk('my/infoAction',async () => {
    // const res = await http.get('url')
    // return res
})

const messageSlice = createSlice({
    name: 'my',
    initialState: {
        token: '',
        infos: {}
    } as UsersState,
    reducers:{
        updateToken(state, action: PayloadAction<Token>){
            state.token = action.payload;
        },
        updateInfos(state, action: PayloadAction<Infos>){
            state.infos = action.payload;
        },
        clearInfos(state){
            state.token = '';
        }
    }
})

export const { updateToken,updateInfos,clearInfos } = messageSlice.actions

export default messageSlice.reducer